Skip to content

Conversation

@ThePassionate
Copy link
Contributor

@ThePassionate ThePassionate commented Jan 20, 2026

Summary

This PR includes three improvements to the OpenSSL mbedtls wrapper:

  1. Export CA certificate loading interfaces - Export SSL_CTX_load_verify_file and SSL_CTX_load_verify_dir functions for loading CA certificates from file or directory.

  2. Fix SSL error code mapping - Correct the return value mapping from mbedtls to OpenSSL conventions:

    • Return 1 for success
    • Return 0 for clean shutdown
    • Return -1 for errors
  3. Align SSL_CTX_new declaration with OpenSSL - Remove the extra rngctx parameter from SSL_CTX_new() to match the standard OpenSSL API signature.

Impact

These changes improve OpenSSL API compatibility, making it easier to port applications that use OpenSSL to NuttX with the mbedtls backend.

Testing

Build and runtime tested on NuttX with mbedtls-based TLS applications.

please ignore openssl mix case warning
Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h:127:23: error: Mixed case identifier found Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h:206:19: error: Mixed case identifier found Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h:208:4: error: Mixed case identifier found Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/openssl_mbedtls_wrapper/include/openssl/ssl.h:211:4: error: Mixed case identifier found

…oad_verify_dir

Export SSL_CTX_load_verify_file() and SSL_CTX_load_verify_dir()
interfaces to allow loading CA certificates from file or directory.

Signed-off-by: makejian <[email protected]>
Map mbedtls error codes to OpenSSL standard return codes in
SSL_connect/SSL_do_handshake:
- Return 1 on success
- Return 0 on controlled shutdown
- Return -1 on fatal error (was returning mbedtls error codes)

This aligns the return values with OpenSSL specification where
SSL_get_error() should be called to get the actual error reason.

Signed-off-by: makejian <[email protected]>
Remove the extra rngctx parameter from SSL_CTX_new() to match
the standard OpenSSL API signature:
  SSL_CTX *SSL_CTX_new(const SSL_METHOD *method)

This improves compatibility with code written for OpenSSL.

Signed-off-by: makejian <[email protected]>
@jerpelea jerpelea changed the title Openssl wrapper export interfaces crypto/openssl-wrapper: export interfaces Jan 20, 2026
@xiaoxiang781216
Copy link
Contributor

@ThePassionate please rebase the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants